// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
// import 'element-ui/lib/theme-chalk/index.css'
//elementui主题
import '../theme/index.css'
//ifonfont
import '@/common/iconfont.css'
//vuex
import store from '@/store/store.js';
import VueParticles from 'vue-particles'

//vant
import Vant from 'vant';
import 'vant/lib/index.css';

//markd文本
import mavonEditor from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'

//进度条
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

//axios
import axios from 'axios';
Vue.prototype.$axios = axios //全局注册，使用方法为:this.$axios

// use
Vue.use(mavonEditor)
Vue.use(Vant);
Vue.use(VueParticles)
// Vue.prototype.$store = store;
Vue.use(ElementUI)
Vue.config.productionTip = false


/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})

//路由拦截
router.beforeEach((to, from, next) => {
    if (to.meta.requireAuth) { // 判断该路由是否需要登录权限
        if (store.state.User.Authorization) { // 通过vuex state获取当前的token是否存在
        NProgress.start();
            next();
        }
        else {
            next({
                path: 'user/login',
                query: {redirect: to.fullPath} // 将跳转的路由path作为参数，登录成功后跳转到该路由
            });
        }
    }
    else {
      NProgress.start();
        next();
    }
});

router.afterEach(transition => {
  NProgress.done();
});
